<!DOCTYPE html>

<head>
    <meta charset="UTF-8">


    </style>
    <script src="../jQuery-3.6.3.min.js"> </script>
    <script>
        $(function () {
         $("#a1").keyup(function(){
            var a=$(this).val();
            $("#he").text(a.length);
         })
        })
    </script>
</head>

<body>

   <input type="text" id="a1" />
   <div>
    字符串长度为：
    <span id="he" >0</span>
   </div>
</body>

</html>